package io.renren.modules.device.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.modules.device.dao.TDeviceThresholdDao;
import io.renren.modules.device.entity.TDeviceThreshold;
import io.renren.modules.device.entity.vo.DeviceThresholdVO;
import io.renren.modules.device.service.TDeviceThresholdService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * //Add the class description
 *
 * @author lhb
 * @date 2023/6/1
 */
@Service("tDeviceThresholdService")
public class TDeviceThresholdServiceImpl extends ServiceImpl<TDeviceThresholdDao, TDeviceThreshold> implements TDeviceThresholdService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
//        IPage<TDeviceEntity> page = this.page(
//                new Query<TDeviceEntity>().getPage(params),
//                new QueryWrapper<TDeviceEntity>()
//        );
        List<DeviceThresholdVO> deviceEntityList = new ArrayList<>();
        String key = (String) params.get("key");
        if (StringUtils.isEmpty(key)) {
            deviceEntityList = this.baseMapper.queryDeviceThresholds();
        } else {
            key = "%".concat(key).concat("%");
            deviceEntityList = this.baseMapper.queryDeviceThresholdsByKeySearch(key);
        }
        return new PageUtils(deviceEntityList, params);
    }

    @Override
    public DeviceThresholdVO getDeviceThresholdInfo(String code) {
        return this.baseMapper.getDeviceThresholdInfoById(code);
    }

	@Override
	public List<DeviceThresholdVO> getDeviceThresholdInfoByDeviceCategoryIdAndAlarmTypeId(Long deviceCategoryID,
			Long alarmTypeID) {
		return  this.baseMapper.getDeviceThresholdInfoByDeviceCategoryIdAndAlarmTypeId(deviceCategoryID, alarmTypeID);
	}
}
